package 动态规划;

/**
 * @author: TTDB
 * @create: 2025/9/24
 */
public class maxProduct {
    public int maxProduct(int[] nums) {
        //数组中乘积最大的非空连续 子数组
        int n = nums.length;
        int[] dpmax = new int[n + 1];
        int[] dpmin = new int[n + 1];
        dpmax[0] = nums[0];
        dpmin[0] = nums[0];
        int res = nums[0];
        for (int i = 1; i < n; i++) {
            dpmax[i] = Math.max(dpmax[i - 1] * nums[i], Math.max(dpmin[i - 1] * nums[i], nums[i]));
            dpmin[i] = Math.min(dpmin[i - 1] * nums[i], Math.min(dpmax[i - 1] * nums[i], nums[i]));
        }
        for (int i = 0; i < n; i++) {
            res = Math.max(res, dpmax[i]);
        }
        return res;
    }
}
